/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BookTransaction;

import Book.BookBean;
import Book.BookDetailsBean;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author mishra
 */
public class getReturnDetials extends HttpServlet {

    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String stuName=null;
            int fine=0, statu=0;
            BookBean bb=new BookBean();
            BookTransBean btb=new BookTransBean();
            BookDetailsBean bdb=new BookDetailsBean();
            
            
            String booknu=request.getParameter("bookno");
            statu=BookTransaction.Query.viewBookStatus(booknu);
            btb=BookTransaction.Query.viewRetDetail(booknu);
            String booknn[]=booknu.split("-");
            bb=Book.Query.viewBook(Integer.parseInt(booknn[2]));
            
            String stuEmpName=btb.getEmployeeAddNo();
            if(stuEmpName.startsWith("emp") || stuEmpName.startsWith("EMP"))
            {
                if(stuEmpName.length()>3){
               String id= stuEmpName.substring(3,stuEmpName.length());
               stuName=User.Query.viewName(Integer.parseInt(id));
               }
            }else{
                //String stuno[]=stuEmpName.split("/");
                //int stuid=Integer.parseInt(stuno[2]);
                stuName=Student.Query.viewName(Integer.parseInt(stuEmpName));
            }
            int latDat=0;
            latDat=btb.getLateDays();
            if(latDat<0){
                fine=0;
                latDat=0;
            }else{
            fine=bb.getFine()*btb.getLateDays();
            latDat=btb.getLateDays();
            }
            if(statu==1){
            out.println(btb.getBookNo()+"--"+btb.getEmployeeAddNo()+"--"+btb.getUserEmail()+"--"+btb.getBookStatus()+"--"+btb.getBookTransactionId()+"--"+btb.getEntryDate()+"--"+btb.getFine()+"--"+btb.getIssueDate()+"--"+btb.getRetruningDate()+"--"+btb.getUserType()+"--"+bb.getBookName()+"--"+btb.getTotalDays()+"--"+latDat+"--"+fine+"--"+bb.getPrice()+"--"+stuName);
            }
            else if(statu==2){
                out.println("2");
            }
            else if(statu==0){
                out.println("0");
            }
            
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(getReturnDetials.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(getReturnDetials.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
